/* 
 *  javascribd - Java client library for the Scribd API. 
 *  Copyright (C) 2009 by Marcel Eyke, http://code.google.com/p/javascribd/ 
 *  Use is subject to license terms of LGPL. See license.txt. 
 */
package com.google.code.javascribd.docs;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import com.google.code.javascribd.connection.ScribdResponse;
import com.google.code.javascribd.type.DocumentId;
import com.google.code.javascribd.type.ErrorType;
import com.google.code.javascribd.type.License;
import com.google.code.javascribd.type.ResponseStatus;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "docs.search")
@XmlRootElement(name = "rsp")
public class SearchResponse implements ScribdResponse {

	@XmlAttribute(name = "stat")
	private ResponseStatus status;

	@XmlElement(name = "error")
	private ErrorType error;

	@XmlElement(name = "result_set")
	private SearchResponse.Set resultSet;

	public ResponseStatus getStatus() {
		return status;
	}

	public ErrorType getError() {
		return error;
	}

	public SearchResponse.Set getResultSet() {
		return resultSet;
	}

	@XmlAccessorType(XmlAccessType.FIELD)
	@XmlType(name = "docs.search.result_set")
	public static class Set {
		@XmlAttribute(name = "list")
		private Boolean list;
		
		@XmlAttribute(name = "totalResultsAvailable")
		private Integer totalResultsAvailable;
		
		@XmlAttribute(name = "totalResultsReturned")
		private Integer totalResultsReturned;
		
		@XmlAttribute(name = "firstResultPosition")
		private Integer firstResultPosition;
		
		@XmlElement(name = "result", type = SearchResponse.Entry.class)
		private List<SearchResponse.Entry> entries;

		public List<SearchResponse.Entry> getEntries() {
			if (entries == null) {
				entries = new ArrayList<SearchResponse.Entry>();
			}
			return entries;
		}

		public Boolean getList() {
			return list;
		}

		public Integer getTotalResultsAvailable() {
			return totalResultsAvailable;
		}

		public Integer getTotalResultsReturned() {
			return totalResultsReturned;
		}

		public Integer getFirstResultPosition() {
			return firstResultPosition;
		}

	}

	@XmlAccessorType(XmlAccessType.FIELD)
	@XmlType(name = "docs.search.result")
	public static class Entry {

		@XmlElement(name = "doc_id")
		private DocumentId docId;

		@XmlElement(name = "title")
		private String title;

		@XmlElement(name = "description")
		private String description;

		@XmlElement(name = "access_key")
		private String accessKey;

		@XmlElement(name = "page_count")
		private Integer pageCount;

		@XmlElement(name = "secret_password")
		private String secretPassword;

		@XmlElement(name = "thumbnail_url")
		private URL thumbnailUrl;

		@XmlElement(name = "tags")
		private String tags;

		@XmlElement(name = "license")
		private License license;

		public DocumentId getDocId() {
			return docId;
		}

		public String getTitle() {
			return title;
		}

		public String getDescription() {
			return description;
		}

		public String getAccessKey() {
			return accessKey;
		}

		public Integer getPageCount() {
			return pageCount;
		}

		public String getSecretPassword() {
			return secretPassword;
		}

		public URL getThumbnailUrl() {
			return thumbnailUrl;
		}

		public String getTags() {
			return tags;
		}

		public License getLicense() {
			return license;
		}

	}

}
